package com.example.myapplication.model.UploadListener;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by yin97 on 2017/6/26.
 */

public class NetProgressInterceptor implements Interceptor {

    private ProgressListener listener;

    public NetProgressInterceptor(ProgressListener listener) {
        this.listener = listener;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        Response originalResponse = chain.proceed(request);
        return originalResponse.newBuilder()
                .body(new ProgressResponseBody(request.url().toString(),originalResponse.body(), listener))
                .build();
    }
}
